<template>
  <div id="safe_audit">
    <p>页面数据的百分比:<el-progress :text-inside="true"  :stroke-width="24" :percentage="max" status="success"></el-progress></p>
    <h2 style="text-align: center">出库调库</h2>
    <!-- 查询条件 -->
    <el-form :inline="true" :model="info" class="demo-form-inline">
      <el-form-item label="请选择仓库id:">
        <el-input v-model="info.search_payId" placeholder="出库单id"></el-input>
      </el-form-item>
      <el-form-item label="请选择出库人:">
        <el-input v-model="info.search_payer" placeholder="入库人"></el-input>
      </el-form-item>
      <el-form-item label="请选择申请人:">
        <el-input v-model="info.search_register" placeholder="申请人"></el-input>
      </el-form-item>
      <el-form-item label="请输入审核时间" required>
        <el-col :span="11">
          <el-form-item prop="date1">

            <el-date-picker type="datetime" v-model="info.search_checkTime1" placeholder="选择日期"
                            value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-form-item prop="date2">
            <el-date-picker type="datetime" v-model="info.search_checkTime2" placeholder="选择日期"
                            value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="search" round>查询按钮</el-button>
      </el-form-item>
    </el-form>
    <!--    入库管理-->
    <el-table :data="arrList1" style="width: 100%">
      <el-table-column prop="payId" label="出库单id" width="150">
      </el-table-column>
      <el-table-column prop="payOrderNumber" label="出库单编号" width="150">
      </el-table-column>
      <el-table-column prop="reason" label="出库理由" width="150">
        <template slot-scope="scope">
          {{ scope.row.reason == "R001-1" ? "平台出库调拨" : (scope.row.checkTag == "R001-2" ? "平台出库调拨2" : "平台出库调拨3") }}
        </template>
      </el-table-column>
      <el-table-column prop="totalAmount" label="总数量" width="150">
      </el-table-column>
      <el-table-column prop="totalPrice" label="总金额" width="150">
      </el-table-column>
      <el-table-column prop="register" label="登记人" width="150">
      </el-table-column>
      <el-table-column prop="checkTag" label="审核状态" width="150">
        <template slot-scope="scope">
          {{ scope.row.checkTag == "S001-3" ? "审核通过" : (scope.row.checkTag == "S001-2" ? "审核未通过" : "等待审核") }}
        </template>
      </el-table-column>
      <!--操作列-->
      <el-table-column label="出库调度" style="width: 50%">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="showById(scope.row.payId)" round>出库调度</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 出库调度弹出对话框 -->
    <el-dialog title="出库调度" :visible.sync="dialogVisible" width="60%">
      <el-form :inline="true" :model="filebean" class="demo-form-inline">
        <el-form-item label="出库单编号">
          <el-input v-model="filebean.payOrderNumber" placeholder="出库单编号"></el-input>
        </el-form-item>
        <el-form-item label="仓库id">
          <el-input v-model="filebean.stockId" placeholder="仓库id"></el-input>
        </el-form-item>
        <el-form-item label="入库人">
          <el-input v-model="filebean.payer" placeholder="出库人"></el-input>
        </el-form-item>
        <el-form-item label="入库理由">
          <el-input v-model="filebean.reason" placeholder="入库理由"></el-input>
        </el-form-item>
        <el-form-item label="总数量">
          <el-input v-model="filebean.totalAmount" placeholder="总数量"></el-input>
        </el-form-item>
        <el-form-item label="总价格">
          <el-input v-model="filebean.totalPrice" placeholder="总价格"></el-input>
        </el-form-item>
<!--         <el-form-item label="申请时间">-->
<!--        <el-input v-model="filebean.registerTime" class="demo-ruleForm" autocomplete="off" readonly></el-input>-->
<!--      </el-form-item>-->

        <el-form-item label="仓库id">
          <el-input v-model="filebean.stockId" placeholder="仓库id"></el-input>
        </el-form-item>
        <el-form-item label="实际出库数量">
          <el-input v-model="filebean.realAmount" placeholder="实际出库数量"></el-input>
        </el-form-item>
        <el-form-item label="应出库数量">
          <el-input v-model="filebean.amount" placeholder="应出库数量"></el-input>
        </el-form-item>
      </el-form>
      <el-table
          :data="tableData"
          style="width: 100%">
        <el-table-column
            prop="payId"
            label="入库单id"
            width="180">
        </el-table-column>
        <el-table-column
            prop="amount"
            label="数量"
            width="180">
        </el-table-column>
        <el-table-column
            prop="stockId"
            label="仓库id">
        </el-table-column>
        <el-table-column
            prop="price"
            label="单价">
        </el-table-column>
        <el-table-column
            prop="subTotal"
            label="小计">
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="edit">确 定</el-button>
      </span>
    </el-dialog>

    <!---分页组件-->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
                   :page-sizes="pageSizeList" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
                   :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  created() {
    this.list()
  },
  data() {
    return {
      arrList1: [],
      tableData: [],
      info: {
        search_gatherId: '',
        search_storer: '',
        search_register: '',
        search_checkTime1: '',
        search_checkTime2: '',
      },
      // 当前页号
      currentPage: 1,
      // 当前页大小
      pageSize: 2,
      // 总记录数
      total: 0,
      // 页大小列表
      pageSizeList: [2, 5, 10, 20],
      dialogVisible: false,
      dialogVisibleCheck: false,
      dialogVisibleAdd: false,
      // 审核表单的对象
      addForm: {

      },
      //定义到对话框的值
      filebean: {

      },
      showGather: {

      },
      max:0,
      registerTime:"",
      checkTime:"",
    }
  },
  methods: {

    async list() {
      const { data: res } = await this.$http.post
      (`/community/pay/twoShow2/${this.currentPage}/${this.pageSize}`)
      this.arrList1 = res.rows
      this.total = res.total
      let aaa=this.total/1
      if(aaa=="Infinity"){
        this.max=0
      }else{
        this.max=aaa
      }
    },
    // async table() {
    //   // let row;
    //   const res = await this.$http.get
    //   (`/community/gather/gatherDetailsById`)
    //   console.log('res',res)
    //   this.tableData = res.data.rows
    // },

    // async showById(index, row) {
    //   await this.table()
    //   const { data: res } = await this.$http.post
    //   (`/community/gather/showById?gatherId=${row.gatherId}`)
    //   this.filebean = res
    //   this.dialogVisible = true
    // },
    async showById(id) {
        const { data: res } = await this.$http.post(`/community/pay/showById?payId=`+id);
        this.filebean = res;
        this.dialogVisible = true;

        const {data:ses} = await this.$http.post
        (`/community/pay/payById?id=`+id)
        this.tableData = ses
        // console.log('ses++++',ses)
        let newAmount = 0;
        for (let i = 0; i < ses.length; i++) {
          let value = ses[i];
          let amount = Number(value.amount); // 将 value.amount 转换为数字
          if (!isNaN(amount)) { // 检查 amount 是否是有效数字
            newAmount += amount; // 将有效的 amount 值累加到 newAmount
          }
        }
        this.filebean.amount = newAmount; // 赋值给 this.filebean.amount
        console.log('newAmount++++', newAmount);
    },

    //修改
    // async edit() {
    //   //拿到仓库id
    //   let stockId = this.stockId
    //   let totalAmount = this.filebean.totalAmount
    //   let parameter = {
    //     stockId,
    //     totalAmount
    //   }
    //   this.getdatatime()
    //   const { data: res } = await this.$http.post
    //   (`/community/pay/updateTWO2`,parameter)
    //   alert("出库成功")
    // },
    //出库调库
    async edit(){
      // console.log(this.filebean)
      console.log(this.tableData)
      const { data: res } =
          await this.$http.post(`/community/pay/update`,this.filebean);
      alert("出库成功")
      this.list()
    },
    getdatatime() {
      var dt = new Date();
      var y = dt.getFullYear();
      var m = (dt.getMonth() + 1).toString().padStart(2, '0');
      var d = dt.getDate().toString().padStart(2, '0');
      var hh = dt.getHours().toString().padStart(2, '0');
      var mm = dt.getMinutes().toString().padStart(2, '0');
      var ss = dt.getSeconds().toString().padStart(2, '0');
      this.checkTime = `${y}-${m}-${d} ${hh}:${mm}:${ss}`
    },
    // 页大小改变
    handleSizeChange(val) {
      this.pageSize = val
      this.list()
    },
    // 页号改变
    handleCurrentChange(val) {
      this.currentPage = val
      // 重新查询
      this.list()
    },
  },
  // 表单查询
  search() {
    // 查询
    this.currentPage = 1
    this.list()
  },
  check() {
    // 获取当前时间
    const now = new Date();
    // 格式化当前时间
    const year = now.getFullYear();
    const month = String(now.getMonth() + 1).padStart(2, '0');
    const day = String(now.getDate()).padStart(2, '0');
    const hours = String(now.getHours()).padStart(2, '0');
    const minutes = String(now.getMinutes()).padStart(2, '0');
    const seconds = String(now.getSeconds()).padStart(2, '0');
    // 设置 addForm.checkTime 为当前时间
    this.addForm.checkTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    // 其他逻辑...
  },
}
</script>

<style></style>